<template>
    <div>
      <!-- 查询参数及按钮部分 -->
      <div class="filter-container">
                  
        <el-dialog  v-dialogDrag  
          :close-on-click-modal="false"
          :title="dialogStatus"
          :visible.sync="dialogEditFormVisible"
          style="padding:0px;"
          width="30%"
        >
          <el-form
            ref="dataForm"
            class="dialog-Backgroundcolor"
            :model="listQuery"
            label-position="right"
            label-width="120px"
          >
            <el-row>
              <el-row style="margin-left:-30px">
                <el-col :span="12">
                  <!-- <el-form-item label="人员类别：">
                    <el-select
                      v-model="formData.state"
                      class="filter-item"
                      placeholder="--请选择--"
                    >
                      <el-option
                        label="全部人员"
                        value=""
                      />
                      <el-option
                        label="在职人员"
                        value="3"
                      />
                      <el-option
                        label="离休人员"
                        value="1"
                      />
                    </el-select>
                  </el-form-item> -->
  
                  <el-form-item label="请选择科室：" prop="deptId">
                      <el-select
                        ref="selectReport"
                        v-model="formData.deptName"
                        class="filter-item"
                        placeholder="--请选择--"
                        :clearable="clearable"
                        @clear="clearHandle"
                      >
                        <el-option
                          :value="formData.deptId"
                          :label="formData.deptName"
                          style="
                            width: 300px;
                            height: 200px;
                            overflow: auto;
                            background-color: #fff;
                          "
                        >
                          <el-tree
                            :data="listTree"
                            :accordion="accordion"
                            :props="defaultProp"
                            :node-key="defaultProp.id"
                            :default-expanded-keys="defaultExpandedKey"
                            @node-click="handleClick"
                          />
                        </el-option>
                      </el-select>
                  </el-form-item>
                  
                  <el-form-item label="姓名：">
                    <el-input v-model="formData.personName" />
                  </el-form-item>
                
                </el-col>
                <!-- <el-col :span="12">
                  <el-form-item label="身份证号码：">
                    <el-input v-model="formData.idenNo" />
                  </el-form-item>
                </el-col> -->
  
              </el-row>
              <el-button
                type="primary"
                style="float:right;"
                @click="handleFilter"
              >
                查询
              </el-button>
            </el-row>
          </el-form>
        </el-dialog>
      </div>
  
      <div>
        <el-dialog
          v-dialogDrag
          :close-on-click-modal="false"
          :before-close="handleClose"
          :title="auditDialogStatus"
          :visible.sync="auditDialogEditFormVisible"
          style="padding:0px;"
          width="30%"
          
        >
          <!-- <el-form
          style="padding:0px;"
              ref="dataForm"
              class="dialog-Backgroundcolor"
              :model="listQuery"
              label-position="right"
              label-width="120px"
          > -->
  
          <el-row>
            <!-- <el-input
                        v-model="treeQuery"
                        suffix-icon="el-icon-search"
                        size="small"
                        class="treeInput"
                    /> -->
            <!-- :Data  属性数据集
                         :props  属性组件配置 -->
            <div style="height:500px;overflow:auto;">
              <el-tree
                id="onlyLeafShow"
                ref="tree"
                node-key="id"
                show-checkbox
                :highlight-current="true"
                :accordion="false"
                :data="agencyTreeData"
                :props="defaultProps"
                :default-expanded-keys="['0']"
                :filter-node-method="filterNode"
              />
            </div>
            <el-button
              type="primary"
              style="float:right;"
              @click="batchHandleAudit"
            >
              批量审核
            </el-button>
          </el-row>
          <!-- </el-form> -->
        </el-dialog>
      </div>
  
      <div>
        <el-row>
          <el-col :span="12">
          <el-select
            v-model="formData.salaryType"
            class="filter-item"
            placeholder="--请选择--"
            @change="handleFilter"
          >
            <el-option label="全部人员" value="" />
            <el-option label="行政人员" value="0" />
            <el-option label="事业人员" value="1" />
            <el-option label="离退休人员" value="11" />
          </el-select>
        </el-col>
        </el-row>
        <el-row style="padding-top: 10px">
          <el-col :span="24">
            <div>单位名称：{{ unitName }}</div>
            <span style="font-size:16px">在编实发合计：{{ Number(reallySendSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}元</span>
            <span style="font-size:16px">（其中：在职合计：{{ Number(workSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}元</span>，
            <span style="font-size:16px">离退休合计：{{ Number(retireSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}元）</span><br>
            <span style="font-size:16px">在编人员：{{ personTotal }}人</span>
            <span style="font-size:16px">（其中：在职：{{ workTotal }}人</span>，
            <span style="font-size:16px">离退休：{{ retireTotal }}人）</span>；
            <span style="font-size:16px">单位增员：{{ unitPlusTotal }}人</span>
            <span style="font-size:16px">（其中：在职：{{ workPlusTotal }}人</span>，
            <span style="font-size:16px">离退休：{{ retirePlusTotal }}人）</span>；
            <span style="font-size:16px">单位减员：{{ unitMinusTotal }}人</span>
            <span style="font-size:16px">（其中：在职：{{ workMinusTotal }}人</span>，
            <span style="font-size:16px">离退休：{{ retireMinusTotal }}人）</span>
          </el-col>
          <!--        <el-col :span="1">-->
          <!--          <el-link type="primary" @click="openAuditExplain">-->
          <!--            <span>审核说明</span>-->
          <!--          </el-link>-->
          <!--        </el-col>-->
        </el-row>
        <!-- 表格部分 -->
        <!-- <div style="height: 420px; width: 99.8%; display: inline-block; vertical-align: top; "> -->
        <el-table
          ref="singalTable"
          v-loading="listLoading"
          :data="list"
          :stripe="true"
          row-key="personId"
          fit
          :height="tableHeight"
          :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        >
          <template slot="empty">
            <tableEmpty />
          </template>
          <el-table-column
            lable=""
            prop="index"
            align="center"
            width="80"
            fixed
          />
          <el-table-column
            label=""
            align="center"
            width="55"
            fixed
          >
            <template slot="header">
              <el-checkbox
                v-model="checkAll"
                :indeterminate="indeterminate"
                @change="handleCheckAll"
              />
            </template>
            <template slot-scope="scope">
              <el-checkbox
                v-if="scope.row.currentMonth === getCurrentMonth"
                v-model="scope.row.check"
                @change="handleCheck(scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="工资月份"
            align="center"
            fixed
          >
            <template slot-scope="{row}">
              <span :style="{ color: row.different === 1 ? 'red':'black' }">{{ row.currentMonth }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="科室"
            align="center"
            fixed
          >
            <template slot-scope="{row}">
              <span :style="{ color: row.different === 1 ? 'red':'black' }">{{ row.deptId | deptNameFilter(that) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="身份证号"
            align="center"
            min-width="180"
            fixed
          >
            <template slot-scope="{row}">
              <span :style="{ color: row.different === 1 ? 'red':'black' }">{{ row.idenNo  }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="姓名"
            align="center"
            fixed
          >
            <template slot-scope="{row}">
              <el-link
                type="primary"
                @click="viewInfo(row)"
              >
                <span :style="{ color: row.different === 1 ? 'red':'black' }">{{ row.personName }}</span>
              </el-link>
            </template>
          </el-table-column>
          <el-table-column
            v-for="item in columnNames"
            :key="item"
            :label="item.split('_')[0] | salaryNameFilter(that)"
            align="center"
            min-width="150"
          >
            <template slot-scope="{row}">
              <div :style="{ float: 'right', color: (row[item.split('_')[0]] !== row[item.split('_')[0] + '_history'] || (row.s1 === 0 && row.s1_history === 0)) && row.currentMonth !== '13月' && row.index !== '合计' ? 'red' : 'black' }">
                <!--获取不带后缀的字段名-->
                <span>{{ Number(row[item.split('_')[0]]).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.limit"
          @pagination="getList"
        />
        <!-- </div> -->
      </div>
                
      <el-dialog  v-dialogDrag  
        title="审核说明"
        :visible.sync="auditFormVisible"
        width="30%"
        max-height="500px"
      >
        <el-form
          ref="auditForm"
          :model="formData"
          label-position="right"
          label-width="120px"
          size="small"
        >
          <el-row>
            <el-col>
              <el-input
                v-model="formData.auditExplain"
                type="textarea"
                :rows="4"
                maxlength="500"
              />
            </el-col>
          </el-row>
          <el-row>
            <el-col
              :span="16"
              style="text-align: right; margin-top:5%"
            >
              <el-button
                type="primary"
                :loading="saveExplainLoading"
                @click="saveExplain"
              >
                确定
              </el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-dialog>
  
      <Enclosure
        ref="enc"
        :middle-table-code="2"
      />
      <PersonSalaryInfo ref="personSalaryInfo" />
      <PersonChangeInfo ref="personChangeInfo" />
      <ApprovalProcess ref="app" />
    </div>
  </template>
  <script>
  import {
    querySalaryNameDict,
    queryReallySendSalarySumAndPersonTotal,
    queryColumnName
  } from '@/api/unitSalaryReport/unitSalaryReport'
  import {
    queryUnitAuditPage,
    audit,
    batchAudit,	 
    rejectAudit,
    returned,
    rejectReturned,
    queryReturnedState 
  } from '@/api/unitSalaryReport/unitOrganization'
  import {getAgencyVerifyBizKey} from "@/api/unitSalaryReport/unitSalaryReport"
  import { queryAgencyNameAndState } from '@/api/unitInformationMaintenance/unitInformationEdit'
  import { getDepartmentList , getDepartmentTree} from '@/api/unitInformationMaintenance/internalOrganizationMaintenance'
  import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  import tableEmpty from '@/components/table/empty'
  import Enclosure from '@/components/Enclosure'
  import PersonSalaryInfo from '@/components/personSalaryInfo/personSalaryInfo'
  import { getAgencyVerifyByAgencyId, getsubmitable } from '@/api/agencyVerify'
  import PersonChangeInfo from '@/components/personChangeInfo/personChangeInfo'
  import ApprovalProcess from '@/components/ApprovalProcess/ApprovalProcess'
  
  import { getFirstAuthAgencyData, getNotAuditAuthAgencyTree } from '@/api/baseInfo'
                                                                                    
  export default {
    name: 'UnitAuditChildren',
    components: { ApprovalProcess, Pagination, tableEmpty, Enclosure, PersonSalaryInfo, PersonChangeInfo },
    filters: {
      deptNameFilter(value, that) {
        const deptNames = that.deptNames
        for (const item of deptNames) {
          if (value === item.code) {
            return item.name
          }
        }
      },
      //号码脱敏显示
      hideMiddle(val) {
        if(val!== undefined&& val!== null){//避免列表中存在空数据报错
          return `${val.substring(0,4)}****${val.substring(val.length-4)}`
        }else{
          return val
        }
      },
      // 工资项滤器
      salaryNameFilter(value, that) {
        const salaryNames = that.salaryNames
        for (const item of salaryNames) {
          if (item.value === value) {
            return item.key
          }
        }
      }
    },
    props: ['tabPane', 'treeData'],
    data() {
      return {
        defaultExpandedKey: [],
        agencyIds:[],
        count: 0,
        datalength: 0,
        agencyTreeData: [],
        firstAuthAgencyData: {},
        defaultProps: {
          id: 'id',
          children: 'children',
          label: 'label'
        },
        treeQuery: '',
        auditDialogStatus: '',
        auditDialogEditFormVisible: false,
        tableHeight: null,
        dialogStatus: '',
        bizKey:'',
        dialogEditFormVisible: false,
        that: this,
        reallySendSalarySum: '0.00',
        workSalarySum: '0.00',
        retireSalarySum: '0.00',
        personTotal: '0',
        workTotal: '0',
        retireTotal: '0',
        unitMinusTotal: '0',
        unitPlusTotal: '0',
        retireMinusTotal: '0',
        workMinusTotal: '0',
        retirePlusTotal: '0',
        workPlusTotal: '0',
        openenClosure: true,
        list: [],
        total: 0,
        listLoading: false,
        clearable: true,
        accordion: false,
        listTree: null,
        defaultProp: {
          children: "children",
          label: "label",
        },
        listQuery: {
          page: 1,
          limit: 200,
          flag: 'all'
        },
        formData: {
          personName:'',//人员姓名
          state: '', // 人员类别
          idenNo: '', // 身份证号码
          auditExplain: '',
          deptId: "",
          deptName: "",
          salaryType:''
        },
        columnNames: [], // 动态表头
        salaryNames: [],
        deptNames: [],
        agencyName: '',
        unitName: '预算单位',
        agencyId: '',
        menuid: this.$router.currentRoute.meta.menuid,
        isSubmitInAgency: 0,
        salaryVerifiedInAgencyCode: '0',
        isSalarySubmit: 0,
        checkAll: false,
        indeterminate: false,
        checkList: [],
        auditFormVisible: false,
        auditFormData: {
          auditExplain: ''
        },
        title1: '',
        saveExplainLoading: false,
        operateAgencyIds: [], // 操作单位id集合
        submitablenum: 0
      }
    },
    computed: {
      getCurrentMonth() {
        return this.list[1].currentMonth
      }
    },
    watch: {
  
      // 单位树的数据组
      treeQuery(val) {
        this.$refs.tree.filter(val)
      },
  
      // 表格的数据数组
      list(val) {
        this.doLayout()
      },
      treeData(val) {
        if (val && val.isleaf === '1') {
          this.unitName = val.label.split('-')[1]
          this.agencyId = val.id
          this.handleTree(val)
          this.getbizKey()
        }
      }
    },
    // 页面初始时执行的方法								   
    created() {
      this.getTreeData()
      this.getFirstAuthAgencyData()
      this.listQuery.flag = this.tabPane
      if (this.treeData && this.treeData.isleaf === '1') {
        this.unitName = this.treeData.label.split('-')[1]
        this.agencyId = this.treeData.id
        this.initDict()
        this.queryAgencyNameAndState()
        this.handleFilter()
        this.getAgencyVerifyByAgencyId()   
        this.getbizKey()
      }
    },
    mounted() {
      this.getTbHeight()
    },
    beforeMount() {
      window.addEventListener('resize', this.getTbHeight)
    },
    methods: {
      // 树点击
      handleClick(data) {
        this.formData.deptId = data.id
        this.formData.deptName = data.label
        if (this.formData.deptName === "组织机构") {
          this.formData.deptId = ""
          this.formData.deptName = ""
        } else {
          this.$refs.selectReport.blur();
        }
      },
      // 清除下拉树选中
      clearHandle() {
        this.formData.deptName = "";
        this.formData.deptId = "";
        this.defaultExpandedKey = [];		
      },
      // 获取数内容
      getTree() {
        getDepartmentTree(this.listQuery).then((response) => {
          this.listTree = response.data;
        });									 
      },
      getFirstAuthAgencyData() {
        getFirstAuthAgencyData().then(res => {
          this.$emit('getFirstAuthAgencyData', res.data)
        })  
      },
      // 获取未审核单位树
      getTreeData() {
        // this.count = 0;
        getNotAuditAuthAgencyTree().then(response => {
          this.agencyTreeData = response.data
        })
      },
      // 树查询过滤
      filterNode(value, data) {
        if (!value) return true
        return data.label.indexOf(value) !== -1
      },
  
      // 选择树
      handleNodeClick(data) {
        this.$emit('handleTreeQuery', data)
      },
      // 退回
      auditReject() {
        this.operateAgencyIds = []
        this.formData.auditExplain = '不同意'
        this.title1 = '退回说明'
        this.auditFormVisible = true
      },
      // 统一保存
      saveExplain() {
        this.saveExplainLoading = true
        this.handleReturned()
      },
      // 获取table高度的方法
      getTbHeight() {
        this.tableHeight = window.innerHeight - 350
      },
      /* 重新渲染table组件 */
      doLayout() {
        this.$nextTick(() => {
          this.$refs.singalTable.doLayout()
        })
      },
      // 获取审核意见
      getAgencyVerifyByAgencyId() {
        getAgencyVerifyByAgencyId(this.listQuery.agencyId).then((response) => {
          this.auditFormData.auditExplain = response.data.auditExplain
        })
      },
      // 打开审核意见
      openAuditExplain() {
        this.auditFormVisible = true
      },
      // 打开批量审核
      queryAudit() {
        this.getTreeData()
        this.auditDialogStatus = '批量审核'
        this.auditDialogEditFormVisible = true
      },  
      // 查询
      query() {
        this.clearHandle();
        this.dialogStatus = '查询'
        this.dialogEditFormVisible = true
      },
      processnode() {
        this.$refs.app.getList( this.bizKey)
      },
        getbizKey(){
       getAgencyVerifyBizKey(this.agencyId).then((response) => {
        this.bizKey = response.data.bizKey;
        });
      },
      // 初始化字典
      initDict() {
        // 查询工资项名称
        querySalaryNameDict(this.listQuery)
          .then(res => {
            this.salaryNames = res.data
          })
          .catch(() => {
            this.salaryNames = []
          })
        // 查询部门名称
        getDepartmentList({ agencyId: this.agencyId })
          .then(res => {
            this.deptNames = res.data
          })
          .catch(() => {
            this.deptNames = []
          })
      },
      // 查看详情
      viewInfo(currenRow) {
        const personId = currenRow.personId.replace('noRepeat', '')
        this.$refs.personSalaryInfo.viewInfo(personId, undefined, this.agencyId)
      },
      queryAgencyNameAndState() {
        // 查询机构名称
        return queryAgencyNameAndState(this.agencyId)
          .then(res => {
            this.agencyName = res.data.agencyName
            this.isSubmitInAgency = res.data.isSubmitInAgency
            this.salaryVerifiedInAgencyCode = res.data.salaryVerifiedInAgencyCode
            this.isSalarySubmit = res.data.isSalarySubmit
          })
          .catch(() => {
            this.agencyName = ''
            this.isSubmitInAgency = 0
            this.salaryVerifiedInAgencyCode = '0'
            this.isSalarySubmit = 0
          })
      },
  
      queryReallySendSalarySumAndPersonTotal() {
        queryReallySendSalarySumAndPersonTotal(this.agencyId, 1)
          .then(res => {
            this.reallySendSalarySum = res.data.reallySendSalarySum
            this.workSalarySum = res.data.workSalarySum
            this.retireSalarySum = res.data.retireSalarySum
            this.personTotal = res.data.personTotal
            this.workTotal = res.data.workTotal
            this.retireTotal = res.data.retireTotal
            this.unitMinusTotal = res.data.unitMinusTotal
            this.unitPlusTotal = res.data.unitPlusTotal
            this.retireMinusTotal = res.data.retireMinusTotal
            this.workMinusTotal = res.data.workMinusTotal
            this.retirePlusTotal = res.data.retirePlusTotal
            this.workPlusTotal = res.data.workPlusTotal
          })
          .catch(() => {
            this.reallySendSalarySum = '0.00'
            this.workSalarySum = '0.00'
            this.retireSalarySum = '0.00'
            this.personTotal = '0'
            this.workTotal = '0'
            this.retireTotal = '0'
            this.unitMinusTotal = '0'
            this.unitPlusTotal = '0'
            this.retireMinusTotal = '0'
            this.workMinusTotal = '0'
            this.retirePlusTotal = '0'
            this.workPlusTotal = '0'
          })
      },
  
      // 动态获取表头
      getColumnNames() {
        Object.assign(this.listQuery, this.formData)
        this.listQuery['agencyId'] = this.agencyId
        queryColumnName(this.listQuery)
          .then(response => {
            this.columnNames = response.data
          })
          .catch(() => {
            this.columnNames = []
          })
      },
      handleTree(data) {
        this.initDict()
        this.queryAgencyNameAndState()
        this.handleFilter()
        this.getAgencyVerifyByAgencyId()
      },
      // 查询
      handleFilter() {
        this.getTree()
        this.listQuery.page = 1
        // this.listQuery.limit = 10
        this.getList()
        this.dialogEditFormVisible = false
      },
  
      // 获取数据
      getList() {
        console.log(this.$router.currentRoute.meta.menuid);
        this.listLoading = true
        this.getTreeData()
        this.getColumnNames()
        var organization = 1;
        this.queryReallySendSalarySumAndPersonTotal()
        Object.assign(this.listQuery, this.formData)
        this.listQuery['agencyId'] = this.agencyId
        this.listQuery['menuid'] = this.menuid
        this.listQuery['organization'] = organization;
        queryUnitAuditPage(this.listQuery)
          .then(response => {
            this.list = response.data.rows
            for (const item of this.list) {
              if (item.children) {
                // table中的row-key需要id不为空且不可重复
                item.children[0].personId += 'noRepeat'
              }
              this.$set(item, 'check', false)
            }
            this.total = response.data.total
            this.initData()
          })
          .catch(() => {
            this.list = []
            this.total = 0
            this.initData()
          })
      },
  
      initData() {
        this.indeterminate = false
        this.listLoading = false
        this.checkList = []
      },
  
       handleClose(done){
         this.$emit('handleBatchAuditBtnLoading')
         this.getTreeData()
         done();
       },
  
      //批量审核
      batchHandleAudit(){
        this.auditDialogEditFormVisible = false
        this.count = 0
        const allAgencyId = this.$refs.tree.getCheckedKeys(true)
        this.datalength = allAgencyId.length
         for (const agencyIds of this.$refs.tree.getCheckedKeys(true)){
          const params = { 'agencyId': agencyIds, 'menuid': this.menuid }
          batchAudit(params)
            .then((response) => {
              this.count += 1
              if (this.count == this.datalength){
                this.$message({
                  message: '审核成功',
                  type: 'success',
                  showClose: true,
                  duration: 4000
                })
                this.getList()
                this.$emit('handleBatchAuditBtnLoading')
              }
            })
            .catch(() => {
              this.getList()
              this.$emit('handleBatchAuditBtnLoading')
            })
        }
      },
      //审核
      handleAudit() {
        console.log(this.total);
        if (this.total === 0) {
          this.$message({
            message: '没有可审核的数据',
            type: 'warning',
            showClose: true,
            duration: 4000
          })
          this.$emit('handleAuditBtnLoading')
          return
        }
        // this.$confirm('确定审核吗？', '提示', {
        //   closeOnClickModal: false,
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // })
        //   .then(() => {
            getsubmitable(this.agencyId).then((response) => {
              this.submitablenum = response.data
              if(this.submitablenum === 0){
              this.$message({
              showClose: true,
              message: '该单位不允许上报',
              type: 'warning',
              duration: 4000
              })
              this.$emit("handleAuditBtnLoading");
              return
              }else{  
                const params = { 'agencyId': this.agencyId, 'menuid': this.menuid ,'organization': 1}
                console.log(this.menuid);
                audit(params)
                  .then((response) => {
                    this.$message({
                      message: '审核成功',
                      type: 'success',
                      showClose: true,
                      duration: 4000
                    })
                    // 刷新数据
                    this.getList()
                    this.$emit('handleAuditBtnLoading')
                  })
                  .catch(() => {
                    this.$emit('handleAuditBtnLoading')
                  })
              }
            }).catch(() => {
                this.$emit('handleAuditBtnLoading')
        })
                  // })
                  // .catch(() => {
                  //   this.$emit('handleAuditBtnLoading')
                  // })
      },
     //撤销审核
      handleRejectAudit() {
        this.queryAgencyNameAndState()
          .then(() => {
            // 上报后不可撤销审核
            // if (this.isSalarySubmit === 1) {
            //   this.$message({
            //     message: '当前单位数据已上报，不可撤销！',
            //     type: 'warning',
            //     showClose: true,
            //     duration: 4000
            //   })
            //   this.$emit('handleRejectAuditBtnLoading')
            //   return
            // }
            if (this.total === 0) {
              this.$message({
                message: '没有可撤销审核的数据',
                type: 'warning',
                showClose: true,
                duration: 4000
              })
              this.$emit('handleRejectAuditBtnLoading')
              return
            }
            // this.$confirm('确定撤销审核吗？', '提示', {
            //   closeOnClickModal: false,
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning'
            // })
            //   .then(() => {
            var organization = 1;
            const params = { 'agencyId': this.agencyId, 'menuid': this.menuid , organization: organization}
            rejectAudit(params)
              .then(() => {
                this.$message({
                  message: '撤销审核成功',
                  type: 'success',
                  showClose: true,
                  duration: 4000
                })
                // 刷新数据
                this.getList()
                this.$emit('handleRejectAuditBtnLoading')
              })
              .catch(() => {
                this.$emit('handleRejectAuditBtnLoading')
              })
          })
          .catch(() => {
            this.$emit('handleRejectAuditBtnLoading')
          })
          // })
          // .catch(() => {
          //   this.$emit('handleRejectAuditBtnLoading')
          // })
      },
  
      handleReturned() {
        if (this.total === 0) {
          this.$message({
            message: '没有可退回的数据',
            type: 'warning',
            showClose: true,
            duration: 4000
          })
          this.$emit('handleReturnedBtnLoading')
          return
        }
        // this.$confirm('确定退回吗？', '提示', {
        //   closeOnClickModal: false,
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // })
        //   .then(() => {
        // formData
        const params = { 'agencyId': this.agencyId, 'menuid': this.menuid, 'auditExplain': this.formData.auditExplain ,'organization': 0 }
        returned(params)
          .then(() => {
            this.$message({
              message: '退回成功',
              type: 'success',
              showClose: true,
              duration: 4000
            })
            // 刷新数据
            this.auditFormVisible = false
            this.saveExplainLoading = false
            this.getList()
            this.$emit('handleReturnedBtnLoading')
          })
          .catch(() => {
            this.$emit('handleReturnedBtnLoading')
          })
          // })
          // .catch(() => {
          //   this.$emit('handleReturnedBtnLoading')
          // })
      },
  
      handleRejectReturned() {
        queryReturnedState(this.agencyId).then(res => {
          if (res.data) {
            rejectReturned(this.agencyId).then(() => {
              this.$message({
                message: '撤销退回成功',
                type: 'success',
                showClose: true,
                duration: 4000
              })
              // 刷新数据
              this.getList()
            })
          } else {
            this.$message({
              message: '没有可撤销退回的数据',
              type: 'warning',
              showClose: true,
              duration: 4000
            })
          }
        })
      },
  
      // 全选
      handleCheckAll(val) {
        for (const item of this.list) {
          item.check = val
        }
        this.indeterminate = false
        this.checkList = val ? this.list : []
      },
  
      // 点击多选按钮
      handleCheck(val, row) {
        this.checkList = []
        const totalCount = this.list.length
        let isCheckedCount = 0
        this.list.forEach(item => {
          if (item.check) {
            this.checkList.push(item)
            isCheckedCount++
          }
        })
        this.checkAll = totalCount === isCheckedCount
        this.indeterminate = isCheckedCount > 0 && isCheckedCount < totalCount
      },
      // 附件方法
      appendixOpen() {
        const selection = this.checkList
        const idList = []
        selection.forEach(item => {
          idList.push({ id: item.personId })
        })
        this.$refs.enc.appendixOpen(idList, false, undefined, this.agencyId)
      },
      // 人员变动情况查询
      getPersonChange() {
        this.$refs.personChangeInfo.getPersonChange(this.agencyId)
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  @import "~@/styles/border.scss"; /*引入公共样式*/
  .el-table {
    .cell {
      .el-table__expand-icon {
        display: none;
      }
  
      .el-table__indent {
        padding-left: 0 !important;
      }
  
      .el-table__placeholder {
        display: none;
      }
    }
  }
  
  ::v-deep.el-table.el-table__expand-icon {
    display: inline-block;
    width: 20px;
    line-height: 20px;
    height: 20px;
    text-align: center;
    margin-right: 3px;
    display: none;
  }
  </style>
  